import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rider/api/api.dart';
import 'package:flutter_rider/module/task/page/order_load_page.dart';
import 'package:flutter_rider/module/task/page/order_unload_page.dart';
import 'package:flutter_rider/module/task/page/task_detail_page.dart';
import 'package:flutter_rider/routers/fluro_navigator.dart';
import 'package:flutter_rider/routers/i_router.dart';

class TaskRouter implements IRouterProvider {
  static String taskPage = '/task';
  static String taskDetailPage = '/task/detail';
  static String orderLoadPage = '/task/orderLoad';
  static String orderUnloadPage = '/task/orderUnload';

  @override
  void initRouter(FluroRouter router) {
    router.define(taskDetailPage,
        handler: Handler(handlerFunc: (context, params) {
      /// 类参数
      final id = context?.settings?.arguments as String;
      return TaskDetailPage(id);
    }));

    router.define(orderLoadPage,
        handler: Handler(handlerFunc: (context, params) {
      /// 类参数
      final id = context?.settings?.arguments as String;
      return OrderLoadPage(id);
    }));

    router.define(orderUnloadPage,
        handler: Handler(handlerFunc: (context, params) {
      /// 类参数
      final id = context?.settings?.arguments as String;
      return OrderUnloadPage(id);
    }));
  }

  // static openTaskLoadDetail(BuildContext context, String id) {
  //   Api.getx(context, "/waybill_mission/detail?id=$id", progress: false,
  //       success: (data) {
  //     // status 小于等于3并且 mission_status 小于5 ，待装货
  //     var status = data["status"];
  //     var mission_status = data["mission_status"];

  //     if (status <= 3 && mission_status < 5) {
  //       NavigatorUtils.push(context, TaskRouter.orderLoadPage, arguments: id);
  //     } else {
  //       NavigatorUtils.push(context, TaskRouter.taskDetailPage, arguments: id);
  //     }
  //   }, failTip: "运单未确认，暂时无法装货", fail: (_) {});
  // }

  // static openTaskUnloadDetail(BuildContext context, String id) {
  //   Api.getx(context, "/waybill_mission/detail?id=$id", progress: false,
  //       success: (data) {
  //     // status 等于 3 并且mission_status 大于5 小于 9 ，待卸货
  //     var status = data["status"];
  //     var mission_status = data["mission_status"];

  //     if (status == 3 && mission_status > 5 && mission_status < 9) {
  //       NavigatorUtils.push(context, TaskRouter.orderUnloadPage, arguments: id);
  //     } else {
  //       NavigatorUtils.push(context, TaskRouter.taskDetailPage, arguments: id);
  //     }
  //   }, failTip: "运单未确认，暂时无法卸货", fail: (_) {});
  // }
}
